from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .routes import employees, templates, contracts
from .database import engine, Base

app = FastAPI()

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 创建数据库表
Base.metadata.create_all(bind=engine)

# 注册路由
app.include_router(employees.router, tags=["employees"])
app.include_router(templates.router, tags=["templates"])
app.include_router(contracts.router, tags=["contracts"])

@app.get("/")
def read_root():
    return {"Hello": "World"} 